package com.demo.app.config;

import com.demo.app.common.auth.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>
 * 主拦截器配置
 * </p>
 *
 * @author zhangxt
 * @date 2023/10/31
 */
@Configuration
public class AuthenticationConfigurer implements WebMvcConfigurer {

    /**
     * <p>
     * 初始化主权限拦截器
     * </p>
     *
     * @return {@link AuthenticationInterceptor}
     */
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login", "/demo/**");
    }
}
